In our wave loop.
Let's do some zombie counting and only spawn zombies when we clear a group.
All right, so how do we do that?
Let's go to workspace.
Hit the plus.
Add a folder.
I'm going to call this folder Zombies.
And what I'm going to do is I'm going to spawn the zombie in that folder, and then I can count the
number of zombies in the folder quite easily.
So we're going to go over to our session utils.
Now I have it here, but if you don't have it, go down to server script service, open it up and you
have your session utils.
Notice that when we do spawn zombies, the parent of the zombie is the workspace.
We need to change that to the folder.
I'm actually going to make a variable for that up top though.
I'm going to say local zombie folder workspace dot zombies.
So we want to change it.
It's easy to find up at the top.
All right.
You can even call that like, monster folder.
Now I'll say zombie folder down here.
Now, when we spawn a zombie, it's going to go in that folder.
It's not going to be spread out all through the workspace.
So now I need to go to my wave loop where I call spawn zombies.
And if you don't have your wav loop, it's down here in server script service, just double click wave
loop.
Cool.
Let's get a reference to our folder.
So a variable for the folder.
Call that zombie folder again.
So don't get confused.
Workspace Zombies.
Now down here where we do our spawning zombies, let's count the number of elements in that folder and
only course bond zombies.
If there's zero.
If it's zero, no zombies left.
I'm going to make a variable called C and short for count with no vowels in it.
C int equals zombie folder Get children.
So I'm going to call the zombie folder variable.
I'm going to do this method called Get Children, which gets everything in the zombie folder, but that's
only zombies.
And then in the front I'm going to say we'll put that a pound sign there.
That's going to get me the number.
That is in this table that was produced by the Get children.
So we're going to get the number of zombies.
Long story short.
Right.
Number of zombies in that folder.
So if count equals equals zero, then.
Will call spawn zombies.
Cool.
All right, So.
I think we got everything we need here.
Let's just produce more zombies.
Let's say ten, and then I'm going to go to my game.
I'm going to play here so I don't have to run up there.
It says Play here.
That's good.
Let's count our zombies.
So I'm going to open up our workspace.
This is my zombie folder.
Here we go.
Getting zombies.
See how they're stacking, though?
We're not giving enough.
Enough spawn locations for the number.
All right, so a couple of zombies died, and now we should stop creating new zombies.
There are some might.
Some might disappear, but we limited it.